package myplaydog.qf.com.yimixianproject.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import myplaydog.qf.com.yimixianproject.R;
import myplaydog.qf.com.yimixianproject.bean.KindNavigationEntity;

/**
 * Created by guqiang on 2016/9/28.
 * User: guqiang
 * Date: 2016/9/28
 * Email:xxxx@163.com
 * Project: YiMiXianProject
 */
public class KindNavigationAdapter extends MyBaseAdapter<KindNavigationEntity.CategoriesBean> {

    public KindNavigationAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder =null;
        if (convertView ==null){
            convertView =getInflater().inflate(R.layout.item_kind_navigation,parent,false);
            viewHolder =new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        KindNavigationEntity.CategoriesBean item =getItem(position);

        if (item.getName()!=null){
            viewHolder.name.setText(item.getName());
        }
        if (TextUtils.isEmpty(item.getSub_name())){
            viewHolder.subName.setVisibility(View.GONE);
        }else {
            viewHolder.subName.setText(item.getSub_name());
        }
        return convertView;
    }

//    @ContentView(R.layout.item_kind_navigation)
//    public class ViewHolder{
//
//        @ViewInject(R.id.item_kind_navigation_name)
//        private TextView name;
//        @ViewInject(R.id.item_kind_navigation_sub_name)
//        private TextView subName;
//        public ViewHolder(LayoutInflater inflater,ViewGroup parent){
//            x.view().inject(this,inflater,parent);
//        }
//    }

    public class ViewHolder{

        @ViewInject(R.id.item_kind_navigation_name)
        private TextView name;
        @ViewInject(R.id.item_kind_navigation_sub_name)
        private TextView subName;
        public ViewHolder(View v){
            x.view().inject(this,v);
        }
    }
}
